package com.kai.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class CodeUtil {

    public static String getCode(){

        char[] chars = new char[52];
        char[] number = {'0','1','2','3','4','5','6','7','8','9'};

        for (int i = 0; i < chars.length; i++) {
            if(i<=25)
                chars[i] = (char) (65+i);
            else
                chars[i] = (char) (97+i-26);

        }

        Random r = new Random();
        ArrayList<Character> code = new ArrayList<>();
        //添加字母
        for (int i = 0; i < 4; i++) {
           code.add(chars[r.nextInt(chars.length)]);
        }
        //添加数字
        for (int i = 0; i < 2; i++) {
           code.add(number[r.nextInt(number.length)]);
        }

        Collections.shuffle(code);
        StringBuilder sb = new StringBuilder();
        for (Character c : code) {
            sb.append(c);
        }
        return sb.toString();

    }


}
